package gui.swing;

import javax.swing.*;
import java.awt.*;

//测试图标，图标是接口，需要实现
public class TestIcon extends JFrame implements Icon {

    private int width;
    private int height;

    public TestIcon(){}//无参构造

    public TestIcon(int width,int height){
        this.width = width;
        this.height = height;
    }

    public void init(){
        TestIcon testIcon = new TestIcon(15, 15);
        //图标放在标签上,也可放在按钮上
        JLabel jLabel = new JLabel("zsh", testIcon, SwingConstants.CENTER);

        Container contentPane = getContentPane();
        contentPane.add(jLabel);

        setVisible(true);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }


    public static void main(String[] args) {
        new TestIcon().init();
    }

    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        g.fillOval(x,y,width,height);
    }

    @Override
    public int getIconWidth() {
        return this.width;
    }

    @Override
    public int getIconHeight() {
        return this.height;
    }
}
